/*
	File:		GameplayState.h
	Course:		SGD 1301
	Author:		Peter Nguyen
	Purpose:	CGameplayState class handles the gameplay
*/

#pragma once

#include "IGameState.h"
#include <vector>

////////////////////////////////////////////////////////////
// SGD Wrappers
// - forward class declaration to reduce header dependencies
// - can ONLY create pointers and references
class CSGD_Direct3D;
class CSGD_DirectInput;
class CSGD_TextureManager;
class CSGD_XAudio2;
class CSGD_MessageSystem;
class IMessage;
class CSGD_EventSystem;

class CEntityManager;
class CEntity;

class CBitmapFont;

struct ParallaxImage;
////////////////////////////////////////////////////////////
// CGameplayState class
//	- game state to handle gameplay
class CGameplayState : public IGameState
{
public:
	////////////////////////////////////////////////////////
	// SINGLETON!
	static CGameplayState* GetInstance( void );

	
	////////////////////////////////////////////////////////
	// IGameState Interface:
	virtual void	Enter	( void );			// load resources
	virtual void	Exit	( void );			// unload resources

	virtual bool	Input	( void );			// handle user input
	virtual void	Update	( float fElapsedTime );	// update game entities
	virtual void	Render	( void );			// render game entities

	////////////////////////////////////////////////////////
	// Message Proc Callback
	static void MessageProc( IMessage* pMsg );

private:
	////////////////////////////////////////////////////////
	// Singleton (not dynamic)
	CGameplayState( void );
	virtual ~CGameplayState( void );
	
	CGameplayState( const CGameplayState& );
	CGameplayState& operator= ( const CGameplayState& );
	
	void LoadTiles();

	void UpdateFPS( float fElapsedTime );
	void RenderDebugs();
	void UnloadTextureHelper(int&id);
	void UnloadMusicHelper(int&id);
	void UnloadSFXHelper(int&id);
	////////////////////////////////////////////////////////
	// SGD Wrappers
	CSGD_Direct3D*			m_pD3D;
	CSGD_DirectInput*		m_pDI;
	CSGD_TextureManager*	m_pTM;
	CSGD_XAudio2*			m_pXA;
	CSGD_MessageSystem*		m_pMS;

	// Other Wrappers
	CEntityManager*			m_pEM;
	CBitmapFont*			m_pFont;

public:
	////////////////////////////////////////////////////////
	// Assets
	int						m_nShipImageID[5];
	int						m_nLaserImageID;
	int						m_nBackgroundMusicID;
	int						m_nLaserShotSfxID;
	int						m_nVictorySfxID;
	int						m_nLoseSfxID;

	int						m_nBackgroundID;
	int						m_nWhiteDotID;
	int						m_nWinScreenID;
	int						m_nLoseScreenID;
	int						m_nGoalID;
	int						m_nBoundID;
	int						m_nMistID;
	int						m_nPowerUp1ID;
	int						m_nPowerUp2ID;
	int						m_nPowerUp3ID;
	int						m_nPowerUp4ID;
	
	ParallaxImage*			parallaxImage;

private:

	////////////////////////////////////////////////////////
	// Entities
	CEntity*				m_pShip;
	float					m_fSpawnRate;
	float					m_fSpawnTimer;

	////////////////////////////////////////////////////////
	// Framerate
	int						m_nFPS;
	int						m_nFrames;
	float					m_fFPSTimer;
	
	//Minimap
	unsigned char 			m_ucMiniMap[128][128];
	void RenderMinimap();
	std::vector<CEntity*> shipVector;

	//Progress bar
	void RenderProgressBar();


	//GameOver
	int m_nGameOver;
	void RenderWinningScreen();
	void RenderLosingScreen();
	void RenderPlayerPlacement();
	float m_fGameOverTimer;
};

